<?php
class PDF extends FPDF{
	var $path;
	var $HREF;
	function PDF(){
		parent::FPDF();
		$this->path = dirname(__FILE__);		
	}
	function Header(){
		//Page header information
		$this->Image($this->path.'/logo4pdf.png',10,8,33);	//Logo
		$this->SetFont('Times','B',30);						//Arial bold 15
		$this->Cell(80);									//Move to the right
		$this->Cell(30,10,'CUSTOMERSHIP FORM',0,2,'C');		//Title
		$this->SetFont('Times','B',13);
		$this->Cell(30,10,'"A FUN LEARNING EXPERIENCE"',0,0,'C');
		$this->Ln(20);										//Line break
	}
	
	function Footer(){										//Page footer information
		$break='<br>';
		$this->WriteHTML($break);
		$this->PrintPolicy($this->path.'/policy.txt');					//return the term and policy from the policy.txt by calling PrintPolicy()
		$this->SetY(217); $this->SetX(168); $this->Cell(3,3,' ',1,0,'C'); // small box to mark check
		$this->SetFont('Times','U',10); $this->SetY(248); $this->SetX(14); $this->Cell(30,10,'______/___/_20____',0,0,'C');
		$this->SetFont('Times','U',10); $this->SetY(248); $this->SetX(160); $this->Cell(30,10,'____________________',0,0,'C');
		$this->SetFont('Times','',10); $this->SetY(253); $this->SetX(14); $this->Cell(30,10,'Date',0,0,'C');
		$this->SetFont('Times','',10); $this->SetY(253); $this->SetX(160); $this->Cell(30,10,'Signature',0,0,'C');
		$this->SetFont('Times','B',14); $this->SetY(258); $this->SetX(80); $this->Cell(30,10,'IMPORTANT',0,0,'C');
		$this->SetFont('Times','',12); $this->SetY(262); $this->SetX(80); $this->Cell(30,10,'Childrens Accident Insurance is only effective upon return of this',0,0,'C');
		$this->SetFont('Times','',12); $this->SetY(266); $this->SetX(80); $this->Cell(30,10,'completed form to your centre',0,0,'C');
		$this->Image($this->path.'/logo4pdf2.png',14,273);	//Logo
	}
	
	function PolicyText($file){
		$f=fopen($file,'r'); 							//Read text file
		$txt=fread($f,filesize($file));
		fclose($f);
		$this->SetFont('Times','',8);					//Set font to Times 12
		$this->MultiCell(0,3,$txt);						//Output justified text
		$this->Ln(); 									//Line break
	}

	function PrintPolicy($file){
			$this->PolicyText($file);					//Print text file
	}

	function WriteHTML($html){
		//HTML parser whenever <BR>, <B>, <I>, <U> & <a for HREF> is used
		$html=str_replace("\n",' ',$html);
		$a=preg_split('/<(.*)>/U',$html,-1,PREG_SPLIT_DELIM_CAPTURE);
		foreach($a as $i=>$e){
			if($i%2==0)	{
				//Text
				if($this->HREF)
					$this->PutLink($this->HREF,$e);
				else
					$this->Write(5,$e);
			}else{
				//Tag
				if($e{0}=='/')
					$this->CloseTag(strtoupper(substr($e,1)));
				else{
					//Extract attributes
					$a2=explode(' ',$e);
					$tag=strtoupper(array_shift($a2));
					$attr=array();
					foreach($a2 as $v)
						if(ereg('^([^=]*)=["\']?([^"\']*)["\']?$',$v,$a3))
							$attr[strtoupper($a3[1])]=$a3[2];
					$this->OpenTag($tag,$attr);
				}
			}
		}
	}

	function OpenTag($tag,$attr){
		//Opening tag
		if($tag=='B' or $tag=='I' or $tag=='U')
			$this->SetStyle($tag,true);
		if($tag=='A')
			$this->HREF=$attr['HREF'];
		if($tag=='BR')
			$this->Ln(5);
	}

	function CloseTag($tag){
		//Closing tag
		if($tag=='B' or $tag=='I' or $tag=='U')
			$this->SetStyle($tag,false);
		if($tag=='A')
			$this->HREF='';
	}

	function SetStyle($tag,$enable){
		//Modify style and select corresponding font
		$this->$tag+=($enable ? 1 : -1);
		$style='';
		foreach(array('B','I','U') as $s)
			if($this->$s>0)
				$style.=$s;
			$this->SetFont('',$style);
	}
}	
?>